package com.gibs.peixunapi.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.Business;

@Repository
public interface BusinessDao extends JpaRepository<Business, Integer>, JpaSpecificationExecutor<Business> {

	@Query("from Business where name = ?1")
	List<Business> find(String name);

	@Query("from Business where name like ?1")
	List<Business> findLike(String name);

	@Query(value = "select * from Business limit ?, ?", nativeQuery = true)
	List<Business> findPage(Integer offset, Integer size);

	@Query(value = "select * from Business where name = ? limit ?, ?", nativeQuery = true)
	List<Business> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from Business where name like ? limit ?, ?", nativeQuery = true)
	List<Business> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from Business where name = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from Business where name like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from Business order by id asc")
	List<Business> findAllAsc();
}

